package com.qudian.pay.core.model;

import java.util.Map;

/**
 * @Description: 通用返回对象
 * @ClassName: CommonResp
*
 * @date 2016年8月17日 下午2:37:58
 * @param <T>
 */
public class CommonResp<T> extends BaseModel {
	
	private static final long serialVersionUID = -6718468217347464132L;
	
	/**
	 * @Fields status : 执行状态
	 */
	private int code;
	
	/**
	 * @Fields msg : 消息
	 */
	private String msg;
	
	private Map<String, Object> extraData;
	
	/**
	 * @Fields data : 数据
	 */
	private T data;
	
	public CommonResp() {
	}
	
	public CommonResp(int code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}
	
	public CommonResp(int code, String msg, T data) {
		super();
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	
	public int getCode() {
		return code;
	}
	
	public void setCode(int code) {
		this.code = code;
	}
	
	public String getMsg() {
		return msg;
	}
	
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public T getData() {
		return data;
	}
	
	public void setData(T data) {
		this.data = data;
	}
	
	public void success() {
		this.code = 200;
		this.msg = "成功";
	}
	
	public void fail() {
		this.code = 0;
		this.msg = "失败";
	}
	
	public void exception() {
		this.code = -1;
		this.msg = "系统异常";
	}
	
	public boolean isSuccess() {
		return code == 200;
	}
	
	public boolean isFailure() {
		return !isSuccess();
	}
	
	public boolean isException() {
		return code == -1;
	}
	
	public Map<String, Object> getExtraData() {
		return extraData;
	}
	
	public void setExtraData(Map<String, Object> extraData) {
		this.extraData = extraData;
	}
}
